#include "Control.hpp"
#include "ContainerControl.hpp"
#include <map>
#include "Application.hpp"
#include "WindowForm.hpp"
using namespace NAMESPACENAME;
extern std::map<HWND, Control*> __mapWindows;
HMENU Control::GetId(ContainerControl* parent)
{
	return reinterpret_cast<HMENU>(parent->childId++);
}
String Control::Text()const
{
	int length(::GetWindowTextLengthW(hWnd));
	Character* pbuffer(new Character[length + 2]);
	::GetWindowTextW(hWnd, pbuffer, length + 2);
	String text(pbuffer);
	delete[] pbuffer;
	return text;
}
int Control::MessageBox(LPCWSTR lpszText, LPCWSTR lpszCaption, UINT style)
{
	return ::MessageBoxW(hWnd, lpszText, lpszCaption, style);
}
void Control::Visibility(enum class Control::Visibility visb)
{
	if (visibility == visb)
		return;
	switch (visb)
	{
	case Visibility::Maximize:
	case Visibility::Visible:
		OnLoad();
		break;
	case Visibility::Hidden:
		OnUnLoad();
		break;
	default:
		terminate();
	}
	visibility = visb;
	if (parent)
	{
		RECT rect(GetParentOffsetRectangle());
		::InvalidateRect(parent->hWnd, &rect, true);
		::UpdateWindow(parent->hWnd);
	}
}
NAMESPACENAME::Rectangle Control::GetParentOffsetRectangle()const
{
	RECT rectP, rectS;
	GetWindowRect(parent->hWnd, &rectP);
	GetWindowRect(hWnd, &rectS);
	rectS.left -= rectP.left;
	rectS.top -= rectP.top;
	rectS.right -= rectP.left;
	rectS.bottom -= rectP.top;
	return NAMESPACENAME::Rectangle(rectS);
}
void Control::OnLeftButtonUp(MouseEventArgs& e)
{
	onLeftButtonUp(this, e);
}
void Control::OnLeftButtonDown(MouseEventArgs& e)
{
	onLeftButtonDown(this, e);
}
void Control::OnRightButtonUp(MouseEventArgs& e)
{
	onRightButtonUp(this, e);
}
void Control::OnRightButtonDown(MouseEventArgs& e)
{
	onRightButtonDown(this, e);
}
void Control::OnMouseMove(MouseEventArgs& e)
{
	onMouseMove(this, e);
}
void Control::OnMouseHover(MouseEventArgs& e)
{
	onMouseHover(this, e);
}
void Control::OnSize(SizeEventArgs& e)
{
	onSize(this, e);
}
void Control::OnSizing(SizingEventArgs& e)
{
	onSizing(this, e);
}
void Control::OnHorizontalScroll(ScrollEventArgs& e)
{
	onHorizontalScroll(this, e);
}
void Control::OnVerticalScroll(ScrollEventArgs& e)
{
	onVerticalScroll(this, e);
}
void Control::OnDestroy()
{
	EventArgs e;
	onDestroy(this, e);
}
void Control::OnLoad()
{
}
void Control::OnUnLoad()
{
}
void Control::OnClose()
{
	EventArgs e;
	onClose(this, e);
}
void Control::OnPaint()
{
}
void Control::OnNcPaint(HRGN hRgn)
{
}
void Control::OnCreate()
{
}
void Control::OnCommand(UINT message, UINT id, Control* control)
{
}